package com.netrust.cmsx.entity.module.site;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.netrust.cmsx.entity.module.cms.Article;

/**
 * 栏目表
 * 
 * @author Administrator
 *
 */
@Entity
@Table(name = "t_site_categories")
public class SiteCategories {

	public static final String LINK = "link";
	public static final String MENU = "menu";
	public static final String OTHER = "other";

	private Integer id;// 主键

	private Integer pid;// 父级栏目外键sc_id【多对一】

	private String name;// 名称

	private String identification;// 自定义标识，不可重复

	private String remark;// 备注

	private String iconUrl;// 图标地址

	private String requestUrl;// 网站栏目请求地址

	private String returnUrl;// 返回地址

	private Integer place;// 排序

	private Boolean enableArticleadd;// 添加文章权限（false：不能添加，true：可以添加）

	private Boolean isNavigation;// 是否在导航条中展示。true为展示，false不展示

	private Boolean isDisplay;// 普通查询时候是否可以Load。true为展示，false不展示

	private Integer dgId;// 栏目分组ID，外键系统字典组表

	private Integer diId;// 栏目分组值，外键系统字典项表

	private String previewUrl;// 栏目预览图片。可保存封面

	private Integer isIndex;// 是否在首页显示

	private Integer isOut;// 是否外部链接

	private Integer linkPath;// 外部链接地址

	@JsonIgnore
	private List<Article> articleList = new ArrayList<Article>();

	@JsonIgnore
	private List<SiteCategories> child = new ArrayList<SiteCategories>();

	// @JsonIgnore
	// private SiteCategories siteCategories;

	public SiteCategories() {
		super();
	}

	public SiteCategories(Integer id) {
		super();
		this.id = id;
	}

	public SiteCategories(Integer id, Integer pid, String name, String identification, String remark, String iconUrl,
			String requestUrl, String returnUrl, Integer place, Boolean enableArticleadd, Boolean isNavigation,
			Boolean isDisplay, Integer dgId, Integer diId, String previewUrl, Integer isIndex, Integer isOut,
			Integer linkPath, List<Article> articleList, List<SiteCategories> child) {
		super();
		this.id = id;
		this.pid = pid;
		this.name = name;
		this.identification = identification;
		this.remark = remark;
		this.iconUrl = iconUrl;
		this.requestUrl = requestUrl;
		this.returnUrl = returnUrl;
		this.place = place;
		this.enableArticleadd = enableArticleadd;
		this.isNavigation = isNavigation;
		this.isDisplay = isDisplay;
		this.dgId = dgId;
		this.diId = diId;
		this.previewUrl = previewUrl;
		this.isIndex = isIndex;
		this.isOut = isOut;
		this.linkPath = linkPath;
		this.articleList = articleList;
		this.child = child;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "sc_id", unique = true, nullable = false)
	public Integer getId() {
		return id;
	}

	/*
	 * @Id
	 * 
	 * @GeneratedValue(strategy = IDENTITY)
	 * 
	 * @Column(name = "sc_id", unique = true, nullable = false)
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	// @Column(name = "sc_p_id", updatable = false, insertable = false)
	@Column(name = "sc_p_id")
	public Integer getPid() {
		return pid;
	}

	public void setPid(Integer pid) {
		this.pid = pid;
	}

	@Column(name = "sc_name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "sc_identification")
	public String getIdentification() {
		return identification;
	}

	public void setIdentification(String identification) {
		this.identification = identification;
	}

	@Column(name = "sc_remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name = "sc_icon_url")
	public String getIconUrl() {
		return iconUrl;
	}

	public void setIconUrl(String iconUrl) {
		this.iconUrl = iconUrl;
	}

	@Column(name = "sc_request_url")
	public String getRequestUrl() {
		return requestUrl;
	}

	public void setRequestUrl(String requestUrl) {
		this.requestUrl = requestUrl;
	}

	@Column(name = "sc_return_url")
	public String getReturnUrl() {
		return returnUrl;
	}

	public void setReturnUrl(String returnUrl) {
		this.returnUrl = returnUrl;
	}

	@Column(name = "sc_place")
	public Integer getPlace() {
		return place;
	}

	public void setPlace(Integer place) {
		this.place = place;
	}

	@Column(name = "sc_enable_article_add")
	public Boolean getEnableArticleadd() {
		return enableArticleadd;
	}

	public void setEnableArticleadd(Boolean enableArticleAdd) {
		this.enableArticleadd = enableArticleAdd;
	}

	@Column(name = "sc_is_navigation")
	public Boolean getIsNavigation() {
		return isNavigation;
	}

	public void setIsNavigation(Boolean isNavigation) {
		this.isNavigation = isNavigation;
	}

	@Column(name = "sc_is_display")
	public Boolean getIsDisplay() {
		return isDisplay;
	}

	public void setIsDisplay(Boolean isDisplay) {
		this.isDisplay = isDisplay;
	}

	@Column(name = "sys_dg_id")
	public Integer getDgId() {
		return dgId;
	}

	public void setDgId(Integer dgId) {
		this.dgId = dgId;
	}

	@Column(name = "sys_di_id")
	public Integer getDiId() {
		return diId;
	}

	public void setDiId(Integer diId) {
		this.diId = diId;
	}

	
	/*@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) // 多对多外键关联的配置
	@JoinTable(name = "t_article_category", joinColumns = {
			@JoinColumn(name = "a_cid", referencedColumnName = "sc_id") }, inverseJoinColumns = {
					@JoinColumn(name = "a_aid", referencedColumnName = "a_id") })*/
	
	// @Transient
	@ManyToMany(mappedBy = "siteCategories")
	public List<Article> getArticleList() {
		return articleList;
	}

	public void setArticleList(List<Article> articleList) {
		this.articleList = articleList;
	}

	// @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY,
	// mappedBy = "siteCategories")
	@Transient
	public List<SiteCategories> getChild() {
		return child;
	}

	public void setChild(List<SiteCategories> child) {
		this.child = child;
	}

	@Column(name = "sc_preview_url")
	public String getPreviewUrl() {
		return previewUrl;
	}

	public void setPreviewUrl(String previewUrl) {
		this.previewUrl = previewUrl;
	}

	@Column(name = "sc_is_index")
	public Integer getIsIndex() {
		return isIndex;
	}

	public void setIsIndex(Integer isIndex) {
		this.isIndex = isIndex;
	}

	@Column(name = "sc_is_out")
	public Integer getIsOut() {
		return isOut;
	}

	public void setIsOut(Integer isOut) {
		this.isOut = isOut;
	}

	@Column(name = "sc_link_path")
	public Integer getLinkPath() {
		return linkPath;
	}

	public void setLinkPath(Integer linkPath) {
		this.linkPath = linkPath;
	}

	// @ManyToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
	// @JoinColumn(name = "sc_p_id", referencedColumnName = "sc_id")
	// public SiteCategories getSiteCategories() {
	// return siteCategories;
	// }
	//
	// public void setSiteCategories(SiteCategories siteCategories) {
	// this.siteCategories = siteCategories;
	// }

	@Override
	public String toString() {
		return "SiteCategories [id=" + id + ", pid=" + pid + ", name=" + name + ", identification=" + identification
				+ ", remark=" + remark + ", iconUrl=" + iconUrl + ", requestUrl=" + requestUrl + ", returnUrl="
				+ returnUrl + ", place=" + place + ", enableArticleAdd=" + enableArticleadd + ", isNavigation="
				+ isNavigation + ", isDisplay=" + isDisplay + ", dgId=" + dgId + ", diId=" + diId + ", previewUrl="
				+ previewUrl + ", isIndex=" + isIndex + ", isOut=" + isOut + ", linkPath=" + linkPath + ", articleList="
				+ articleList + ", child=" + child + "]";
	}
}